import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2023-01-31
 * Time: 10:58
 */
class MyThreadPool{
    BlockingDeque<Runnable> queue=new LinkedBlockingDeque<>();
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }

    public MyThreadPool(int m){
        for(int i=0;i<m;i++) {
            Thread t = new Thread(() -> {
                while (true) {
                    try {
                        Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }

            });
            t.start();
        }
    }

}
public class test4 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool=new MyThreadPool(5);
        for(int i=0;i<1000;i++){
            int taskId=i;
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("执行当前的任务"+taskId+" 当前线程"+Thread.currentThread().getName());
                }
            });
        }
    }
}
